classdef FuzzyCommand
    properties
        Name            % 命令名称
        Center          % 高斯中心
        Sigma1           % 标准差1
        Sigma2           % 标准差2
        CurrentProb     % 当前时刻概率
        History         % 历史概率记录
        HMembership      % 隶属度
        LMembership
        mu_upper
        mu_lower
    end
    
    methods
        function obj = FuzzyCommand(name, c, sigma, rho)
            obj.Name = name;
            obj.Center = c;
            obj.Sigma1 = sigma;
            obj.Sigma2 = sigma+1-rho;
            obj.CurrentProb = 0;
            obj.History = [];
        end
        
        function obj = compute_membership(obj, x)
            % 计算高斯隶属度（二型）
            mu_upperraw = exp(-(x - obj.Center)^2 / (2 * obj.Sigma1^2));
            mu_lowerraw = exp(-(x - obj.Center)^2 / (2 * obj.Sigma2^2));
            obj.mu_upper = max(mu_lowerraw,mu_upperraw);
            obj.mu_lower = min(mu_lowerraw,mu_upperraw);
            obj.HMembership = [obj.mu_lower,obj.mu_upper];
            muL_upper = 1 - obj.mu_lower;
            muL_lower = 1 - obj.mu_upper;
            obj.LMembership = [muL_lower, muL_upper];
        end
        
        function obj = record_history(obj, ~)
            % 记录当前概率到历史
            obj.History = [obj.History;obj.HMembership];
        end
    end
end